Array.prototype.selfForEach = function(fn) {
  for(let i = 0; i < this.length; i++) {
    fn(this[i], i, this);
  }
};

Array.prototype.selfReduce = function(fn, resultType) {
  let defaultNum = 0;
  if (resultType === undefined) {
    resultType = this[0];
    defaultNum = 1;
  }
  for(let i = defaultNum; i < this.length; i++) {
    resultType = fn(resultType, this[i], i, this);
  }
  return resultType;
};

Array.prototype.selfFilter = function(fn) {
  const result = [];
  for(let i = 0; i < this.length; i++) {
    if (fn(this[i])) {
      result.push(this[i]);
    };
  }
  return result;
};

const arr = [1, 2, 3, 4, 5];
arr.selfForEach((item, index, list) => {
  console.log(item);
  console.log(index);
  console.log(list);
});

arr.forEach((item, index, list) => {
  // console.log(item, 'item');
  // console.log(index, 'index');
  // console.log(list, 'list');
});

const filterArr = arr.selfFilter(item => !(item % 2));

// console.log(filterArr, 'filter');
